package com.shen.accountbook.module.home.detailedfragment;

import android.content.Context;

import com.shen.accountbook.bean.ReportFormsBean;
import com.shen.accountbook.bean.temp.NoteBeanTemp;
import com.shen.accountbook.bean.temp.biz.NoteBeanTempBiz;
import com.shen.accountbook.module.base.BasePresenter;
import com.shen.accountbook.utils.L;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * author:  shen
 * date:    2018/6/27
 */
public class DetailPresenterImpl extends BasePresenter<DetailView, DetailModelImpl> {

    public DetailPresenterImpl(Context context, DetailView mvpView) {
        super(context, mvpView);
    }

    @Override
    protected DetailModelImpl createModel() {
        return new DetailModelImpl();
    }


    /**
     * 数据库中获取"三级分类" -- 根据第一分类获取第三分类
     * @return
     */
    public void getBeanByDate(String date) {
        NoteBeanTempBiz biz = new NoteBeanTempBiz();
        biz.getBeanByDate(date, new Observer<List<NoteBeanTemp>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<NoteBeanTemp> noteBeanTemps) {
                mvpView.setData(noteBeanTemps);
            }


            @Override
            public void onError(Throwable e) {
                L.i("getBeanByDate -- error :" , e);
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 数据库中获取"三级分类" -- 根据第一分类获取第三分类
     * @return
     */
    public void getBeanByDateReport(String date) {
        NoteBeanTempBiz biz = new NoteBeanTempBiz();
        biz.getBeanByDateReport(date, new Observer<ReportFormsBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ReportFormsBean reportFormsBean) {
                L.i(" reportFormsBean.toString() --- " + reportFormsBean.toString());
            }

            @Override
            public void onError(Throwable e) {
                L.i("getBeanByDate -- error :" , e);
            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void getBeanAll(){
        NoteBeanTempBiz biz = new NoteBeanTempBiz();
        mvpView.setData(biz.getNoteBean());
    }
}
